package com.cgbl.cg.ui.vip

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.cgbl.cg.BR
import com.cgbl.cg.R
import com.cgbl.cg.databinding.AppActivityPayResultBinding
import com.cgbl.cg.vm.order.PayResultViewModel
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.base.util.arouter.ARouterUtil
import com.robot.base.utils.PayUtils

@Route(path = AppConstants.Router.Mine.A_MINE_PAY_RESULT)
class PayResultActivity : GLBaseActivity<AppActivityPayResultBinding, PayResultViewModel>() {

    private var orderType = 0
    private var payResult = PayUtils.PAY_FAILED
    override fun initComponents() {
        initTiterBar()
        initView()
    }

    override fun initViewObservable() {
        val ivlogo = findViewById<ImageView>(R.id.iv_logo)
        val title = findViewById<TextView>(R.id.tv_title)
        val tvFunction1 = findViewById<TextView>(R.id.tv_function1)
        ivlogo.setImageResource(if (payResult == PayUtils.PAY_SUCCESS) R.mipmap.ic_pay_success else R.mipmap.ic_pay_failed)
        title.text = if (payResult == PayUtils.PAY_SUCCESS) "支付成功" else "支付失败"
        tvFunction1.text = if (payResult == PayUtils.PAY_SUCCESS) "查看订单" else "继续支付"

        tvFunction1.setOnClickListener {
            if (payResult == PayUtils.PAY_SUCCESS) {
                //查看订单
                finish()
            } else {
                //继续支付
            }
        }
        findViewById<View>(R.id.tv_home).setOnClickListener {
            ARouterUtil.goToActivity(AppConstants.Router.Main.A_MAIN)
        }
    }


    private fun initTiterBar() {
        val titleView = findViewById<TextView>(R.id.tv_title)
        val backView = findViewById<ImageView>(R.id.iv_back)
        titleView.text = if (payResult == PayUtils.PAY_SUCCESS) "支付成功" else "支付失败"
        backView.setOnClickListener { finish() }
    }

    private fun initView() {

    }

    override fun initParam() {
        payResult = intent.getIntExtra(AppConstants.BundleKey.PAY_RESULT, PayUtils.PAY_FAILED)
        orderType = intent.getIntExtra(
            AppConstants.BundleKey.ORDER_TYPE, AppConstants.BundleValue.ORDER_TYPE_COURSE
        )
    }

    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_pay_result

    override fun initVariableId(): Int = BR.viewModel
}